﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using Webdiver;


namespace AnyOffice.general.vehicle
{
    public partial class order_detail : ModulePage
    {
        public void ChangePage(object src, PageChangedEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            this.BindData();
        }
        public string GetStatusDesc(int status)
        {
            switch (status)
            {
                case 0:
                    return "待批";

                case 1:
                    return "已准";

                case 2:
                    return "未准";
            }
            return "";
        }
        private void BindData()
        {
            DataTable table = new VehicleUsageDao().SelectPagedByVehicleId(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, false, Convert.ToInt32(this.ViewState["VehicleId"].ToString()));
            this.ViewState["CurrentRowNums"] = table.Rows.Count;
            this.ViewState["CurrentPage"] = this.AspNetPager1.CurrentPageIndex.ToString();
            this.rptVehicleUsage.DataSource = table;
            this.rptVehicleUsage.DataBind();
            this.litNavCount.Text = "<span class=\"small1\">共&nbsp;<span class=\"big4\">" + this.AspNetPager1.RecordCount.ToString() + "</span>&nbsp;条车辆记录";
            this.litNavPager.Text = "<span class=\"small1\">当前为第" + this.AspNetPager1.CurrentPageIndex.ToString() + "页，共" + this.AspNetPager1.PageCount.ToString() + "页，每页最多" + this.AspNetPager1.PageSize.ToString() + "条</span>";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int vehicleId = (Request.QueryString["vehicle_id"] != null) ? int.Parse(Request.QueryString["vehicle_id"]) : 0;
                this.ViewState["VehicleId"] = vehicleId;
                DataTable table = new VehicleDao().SelectByVehicleId(base.Conn, vehicleId);
                if (table.Rows.Count > 0)
                {
                    this.litNavTitle.Text = table.Rows[0]["Number"].ToString();
                }
                DataTable table2 = new VehicleUsageDao().SelectPagedByVehicleId(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, true, vehicleId);
                if (int.Parse(table2.Rows[0][0].ToString()) == 0)
                {
                    this.litNavCount.Visible = false;
                    this.litNavPager.Visible = false;
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowMessage("无预订信息");
                }
                else
                {
                    this.AspNetPager1.RecordCount = int.Parse(table2.Rows[0][0].ToString());
                    this.BindData();
                }
            }
        }

 

    }
}
